package view.component.weapon.flute
{
	import enums.main.UISize;
	
	import feathers.controls.Button;
	import feathers.controls.Label;
	
	import model.vo.weapon.FluteVo;
	
	import starling.events.Event;
	
	import util.FG2FUGenerator;
	import util.WeaponUtil;
	
	import view.component.weapon.BaseShortWeaponDetailView;
	import view.event.weapon.flute.FluteDetailViewEvent;
	
	/**
	 * 笛子-详细信息界面
	 * @author £iang
	 * 
	 */	
	public class FluteDetailView extends BaseShortWeaponDetailView
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 音色标题 */
		public var melodyTitle:Label;
		/** 音色信息 */
		public var melodyBtn:Button;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		/** 笛子信息 */
		private var _fluteVo:FluteVo;
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 初始化函数 
		 * 
		 */		
		override protected function initialize():void
		{
			super.initialize();
			melodyTitle = new Label();
			melodyTitle.text = "   音色：";
			mainSC.addChild( melodyTitle );
			
			melodyBtn = FG2FUGenerator.generateRoundRectButton(
				UISize.TAB_BUTTON_W3, UISize.TAB_BUTTON_H,
				this.dpiScale, UISize.TAB_BUTTON_H * 0.9, "small"
			);
			mainSC.addChild( melodyBtn );
			
			addListener();
		}
		
		/**
		 * 绘制函数 
		 * 
		 */		
		override protected function draw():void
		{
			super.draw();
			melodyTitle.x = 20 * this.dpiScale;
			melodyTitle.y = 300 * this.dpiScale;
			melodyBtn.x = 150 * this.dpiScale;
			melodyBtn.y = 300 * this.dpiScale;
			drawPart();
		}
		
		/**
		 * 设置狩猎笛数据 
		 * @param fluteVo 狩猎笛数据
		 * 
		 */		
		public function setFluteData( fluteVo:FluteVo ):void
		{
			_fluteVo = fluteVo;
			setShortData( fluteVo );
			melodyBtn.label = WeaponUtil.getMelodyText( fluteVo.melody );
		}
		
		/**
		 * 添加侦听 
		 * 
		 */		
		public function addListener():void
		{
			melodyBtn.addEventListener( Event.TRIGGERED, melodyBtnTriggeredHandler );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 *  处理点击音色按钮后派发的事件
		 * @param event 点击音色按钮后派发的事件
		 * 
		 */		
		protected function melodyBtnTriggeredHandler( event:Event ):void
		{
			var mEvent:FluteDetailViewEvent = new FluteDetailViewEvent(
				FluteDetailViewEvent.SHOW_MELODY	
			);
			
			mEvent.melodyType = WeaponUtil.getMelodyType( _fluteVo.melody );
			dispatchCommonEvent( mEvent );
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构函数 
		 * 
		 */		
		override public function dispose():void
		{
			melodyTitle.dispose(); melodyTitle = null;
			melodyBtn.dispose(); 
			FG2FUGenerator.deepDisposeButtonComp( melodyBtn );
			melodyBtn = null;
			super.dispose();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function FluteDetailView()
		{
			super();
			weaponType = "flute";
			insertOffset = 60;
		}
	}
}